package com.egov.wrdmp.reporting.controller;
import java.util.Iterator;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.egov.wrdmp.reporting.model.Report;
import com.egov.wrdmp.reporting.service.ReportService;

@Controller
@SessionAttributes
public class ReportController {
	
	@Autowired
    public ReportService reportService;
 
    @RequestMapping("/index")
   // @ModelAttribute("reportList")
   // public String listReport(Map<String, Object> map) {
    public String listReport(Model model) {
    	model.addAttribute("report", new Report());
    	model.addAttribute("reportList", reportService.listReport());
        for(int i=0;i<reportService.listReport().size();i++){
        	Report tmpReport = reportService.listReport().get(i);
        	System.out.println("Report Name is "+tmpReport.getReportName());
        }
        
        return "report";
    }
 
    @RequestMapping(value = "/add.html", method = RequestMethod.POST)
    public String addReport(@ModelAttribute("report")
    Report report, BindingResult result) {
 
    	reportService.addReport(report);
 
        return "redirect:/index";
    }
 
    @RequestMapping("/delete/{reportId}")
    public String deleteContact(@PathVariable("reportId")
    Integer reportId) {
 
        reportService.removeReport(reportId);
 
        return "redirect:/index";
    }

	public ReportService getReportService() {
		return reportService;
	}

	public void setReportService(ReportService reportService) {
		this.reportService = reportService;
	}
    
}
